package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;

	[SWF(width="700", height="700", frameRate="24", backgroundColor="0xFFFFFF")]
	public class mouseEventEnabled_Test extends Sprite
	{
		private var lower:Sprite;
		private var upper:Sprite;

		public function mouseEventEnabled_Test()
		{
			this.addEventListener(Event.ADDED_TO_STAGE, addToStageHandler, false, 0, true);
		}

		private function addToStageHandler($event:Event):void
		{
			trace("#### addToStageHandler ####");
			this.removeEventListener(Event.ADDED_TO_STAGE, addToStageHandler);

			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;

			var count:int = 0;
			if (stage.stageWidth === 0 && stage.stageHeight === 0)
			{
				stage.addEventListener(Event.ENTER_FRAME, function($event:Event):void
					{
						if (stage.stageWidth > 0 || stage.stageHeight > 0)
						{
							stage.removeEventListener($event.type, arguments.callee);
							init();
						}
					//trace(++count); //IE8에서 두번 들어왔다. 26.                
					});
			}
			else
			{
				init();
			}
		}

		private function init():void
		{
			trace("#### init ####");

			lower = new Sprite();
			lower.name = "lower";
			lower.x = 40;
			lower.y = 40;
			lower.graphics.beginFill(0x0000FF, 1);
			lower.graphics.drawRect(0, 0, 100, 100);
			lower.graphics.endFill();
			this.addChild(lower);

			upper = new Sprite();
			upper.name = "upper";
			upper.graphics.lineStyle(1, 0x000000);
			upper.graphics.drawRect(0, 0, 100, 100);
			lower.graphics.endFill();
			this.addChild(upper);

			var upperSprite1:Sprite = new Sprite();
			upperSprite1.x = 0;
			upperSprite1.y = 50;
			upperSprite1.graphics.beginFill(0x00FFFF, .6);
			upperSprite1.graphics.drawRect(0, 0, 60, 50);
			upperSprite1.graphics.endFill();
			upper.addChild(upperSprite1);

			var upperSprite2:Sprite = new Sprite();
			upperSprite2.x = 40;
			upperSprite2.y = 0;
			upperSprite2.graphics.beginFill(0x00FF00, .6);
			upperSprite2.graphics.drawRect(0, 0, 60, 60);
			upperSprite2.graphics.endFill();
			upper.addChild(upperSprite2);

			lower.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler, false, 0, true);
			upper.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler, false, 0, true);

			//Enabled(new Enabled).target(this).enabled(false, false);
			//Enabled(new Enabled).target(lower).enabled(false, false);
		}

		private function mouseOverHandler($event:MouseEvent):void
		{
			trace("currentTarget : ", $event.currentTarget.name.toString());
		}
	}
}